<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="服务器" prop="serviceName">
        <el-select v-model="queryParams.serviceId" placeholder="请选择">
          <el-option
            v-for="item in serviceLists"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="参数名称" prop="name">
        <el-input
          v-model="queryParams.squadName"
          placeholder="请输入steam64id或小队名字"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>

    <el-table stripe v-loading="loading" :data="configList" >
      <el-table-column label="小队ID" align="center" prop="squadID" />
      <el-table-column label="小队名称" align="center" prop="squadName" :show-overflow-tooltip="true" />
      <el-table-column label="阵营ID" align="center" prop="teamID" :show-overflow-tooltip="true" />
      <el-table-column label="阵营" align="center" prop="teamName" :show-overflow-tooltip="true" />
      <el-table-column label="队长名称" align="center" prop="creatorName" :show-overflow-tooltip="true" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button type="primary" @click="handleJS(scope.row)">解散小队</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { getTeamList} from "@/api/suqad/player";
import { disbandSquad} from "@/api/suqad/rcon";
import store from '@/store'
export default {
  name: "TeamInfo",
  dicts: ['sys_yes_no'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 参数表格数据
      configList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      serviceLists: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        squadName: undefined,
        serviceId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        configName: [
          { required: true, message: "参数名称不能为空", trigger: "blur" }
        ],
        configKey: [
          { required: true, message: "参数键名不能为空", trigger: "blur" }
        ],
        configValue: [
          { required: true, message: "参数键值不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.serviceLists = store.getters.serviceLists
    this.queryParams.serviceId = this.serviceLists[0].id
    this.getList();
  },
  methods: {
    /** 查询参数列表 */
    getList() {
      this.loading = true;
      getTeamList(this.queryParams).then(response => {
          this.configList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      ).catch(e => {
        this.loading = false
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        configId: undefined,
        configName: undefined,
        configKey: undefined,
        configValue: undefined,
        configType: "Y",
        remark: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    handleJS(row) {
      console.log(row)
      this.$confirm('确定要解散该小队吗', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        disbandSquad({
          serviceId: this.queryParams.serviceId,
          teamId:row.teamID,
          squadId:row.squadID
        }).then(res=>{
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        })

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    }

  }
};
</script>
